//
//  BBEShowViewController.swift
//  PictureShow
//
//  Created by apple on 16/4/27.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class BBEShowViewController: UIViewController {

    let ID = "cell"
    
    var showModel : BBEPictureModel?
    
    lazy var closeBtn : UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
        
        btn.setTitle("关 闭", forState: UIControlState.Normal)
        btn.backgroundColor = UIColor.grayColor()
        btn.addTarget(self, action: "close", forControlEvents:.TouchUpInside)
        
        return btn
    }()
    
    lazy var saveBtn : UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
        
        btn.setTitle("保 存", forState: UIControlState.Normal)
        btn.backgroundColor = UIColor.grayColor()
        btn.addTarget(self, action: "save", forControlEvents:.TouchUpInside)
        
        return btn
    }()
    
    lazy var collectionView : UICollectionView = {
        
        let collection = UICollectionView(frame: CGRectZero, collectionViewLayout: BBEShowFlowLayout())
        
        collection.frame = UIScreen.mainScreen().bounds
        
        collection.dataSource = self
        collection.delegate = self
        
        return collection
        
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

       view.addSubview(collectionView)
        view.addSubview(saveBtn)
        view.addSubview(closeBtn)
        
        let btnx : CGFloat = 20
        let btny : CGFloat = UIScreen.mainScreen().bounds.height - 20 - 32
        let btnw : CGFloat = 80
        let btnh : CGFloat = 32
        let btnx1 : CGFloat = UIScreen.mainScreen().bounds.width - 20 - 80
        closeBtn.frame = CGRect(x: btnx, y: btny, width: btnw, height: btnh)
        saveBtn.frame = CGRect(x: btnx1, y: btny, width: btnw, height: btnh)
        
        // 注册cell
        collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: ID)
    }
    
    
    func close()
    {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func save()
    {
        print("_______")
    }
    
}

extension BBEShowViewController : UICollectionViewDataSource, UICollectionViewDelegate{
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return 2
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ID, forIndexPath: indexPath)
        
        cell.backgroundColor = UIColor.yellowColor()
        
        return cell
    }
    
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        
        
    }
}
